import { Ref } from 'vue'

/**
 * @description 数值动画函数
 * @param startNum {number} 起始数字
 * @param endNum {number} 结束数字
 * @param duration {number} 持续时间
 * @return {num: ref<number>}
 */
export function numberAnimation(startNum, endNum, duration): Ref<number> {
  const num = ref(startNum)
  const time = setInterval(() => {
    if (num.value < endNum) num.value += 1
    else clearInterval(time)
  }, duration / endNum - startNum)
  return num
}
